package com.sunmouse.toolkit.util;

import android.app.Activity;
import android.support.annotation.DrawableRes;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.sunmouse.toollib.utils.StringUtils;
import com.sunmouse.toolkit.R;

/**
 * Created by Administrator on 2017/8/10.
 */
public class NavUtils {
    private ImageView backIv;
    private TextView titleTv;
    private ImageView nextIv;

    private NavUtils(Activity act) {
        this.backIv = (ImageView) act.findViewById(R.id.back_iv);
        this.titleTv = (TextView) act.findViewById(R.id.title_tv);
        this.nextIv = (ImageView) act.findViewById(R.id.next_iv);
    }

    /**
     * nav factory
     *
     * @param act
     * @return
     */
    public static NavUtils newInstance(Activity act) {
        return new NavUtils(act);
    }

    /**
     * click event
     */
    public void setOnBackClickListener(View.OnClickListener listener) {
        this.backIv.setOnClickListener(listener);
    }

    public void setOnNextClickListener(View.OnClickListener listener) {
        this.backIv.setOnClickListener(listener);
    }

    /**
     * set content
     */
    public void setBackIcon(@DrawableRes int resId) {
        this.backIv.setImageResource(resId);
    }

    public void setNextIcon(@DrawableRes int resId) {
        this.backIv.setImageResource(resId);
    }

    public void setTitle(String msg) {
        if (StringUtils.isEmpty(msg)) msg = "";
        this.titleTv.setText(msg);
    }

    /**
     * set visibility
     */
    public void setBackVisibility(int visibility) {
        this.backIv.setVisibility(visibility);
    }

    public void setNextVisibility(int visibility) {
        this.nextIv.setVisibility(visibility);
    }

    public void setTitleVisibility(int visibility) {
        this.titleTv.setVisibility(visibility);
    }
}
